<template>
  <div>
    <el-form ref="ruleForm" :model="obj" :rules="rules">
      <h2 class="title">动火方案审批表</h2>
      <table>
        <tr>
          <td>选择项目</td>
          <td colspan="4">
            <el-form-item prop="spaceId">
              <el-select v-model="obj.spaceId" placeholder="请选择">
                <el-option v-for="item in passProjectData" :key="item.spaceId" :label="item.name" :value="item.spaceId" />
              </el-select>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td colspan="1">附件:</td>
          <td colspan="4">
            <el-form-item prop="fileUrl">
              <wise-file v-model="obj.fileUrl" accept=".doc,.pdf" upload-type="file" :limit="6" />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td>编号:</td>
          <td>
            <el-form-item prop="serialNumber">
              <el-input v-model="obj.serialNumber" placeholder="请输入" />
            </el-form-item>
          </td>
          <td>方案名称:</td>
          <td colspan="2">
            <el-form-item prop="name">
              <el-input v-model="obj.name" placeholder="请输入" />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td rowspan="5">一、施工组织</td>
          <td colspan="1">动火申请单位:</td>
          <td colspan="3">
            <el-form-item prop="hotApplyUnit">
              <el-input v-model="obj.hotApplyUnit" placeholder="请输入" />
            </el-form-item>
          </td>
        </tr>

        <tr>
          <td colspan="1">动火作业时间:</td>
          <td colspan="3">
            <el-form-item prop="value1">
              <el-date-picker
                v-model="value1"
                type="datetimerange"
                value-format="timestamp"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="timeChange"
              />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td>基层战场(作业区)负责人:</td>
          <td>
            <el-form-item prop="workAdminUserName">
              <el-input v-model="obj.workAdminUserName" placeholder="请输入" />
            </el-form-item>
          </td>
          <td>动火作业级别:</td>
          <td>
            <el-form-item prop="hotLevel">
              <el-input v-model="obj.hotLevel" placeholder="请输入" />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td colspan="1">动火作业地点:</td>
          <td colspan="3">
            <el-form-item prop="hotPlace">
              <el-input v-model="obj.hotPlace" placeholder="请输入" />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td>动火作业单位负责人:</td>
          <td>
            <el-form-item prop="hotWorkUnitAdmin">
              <el-input v-model="obj.hotWorkUnitAdmin" placeholder="请输入" />
            </el-form-item>
          </td>
          <td>动火作业单位监护人:</td>
          <td>
            <el-form-item prop="hotWorkUnitGuardian">
              <el-input v-model="obj.hotWorkUnitGuardian" placeholder="请输入" />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td colspan="1">二、动火作业内容及目的</td>
          <td colspan="4">
            <el-form-item prop="hotContent">
              <el-input v-model="obj.hotContent" type="textarea">placeholder="请输入"</el-input>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td colspan="5">
            三、动火作业部位与周围油气流程及置换隔断示意图（管线要注明介质、尺寸，控制流程中的阀门要编号，由动火申请单位绘制，生产部门审核）

            <div>
              <el-form-item prop="sketchMap">
                <wise-file v-model="obj.sketchMap" upload-type="image" :limit="6" />
              </el-form-item>
            </div>
            <p class="textRight">
              绘制：
              <el-input v-model="obj.drawUser" class="label_put" type="input" placeholder="请输入" />
            </p>
            <p class="textRight">
              审核：
              <el-input v-model="obj.processUser" class="label_put" type="input" placeholder="请输入" />
            </p>
            <p class="textCenter">（特级、一级由生产科工艺设备管理人员审核，二级由作业区工艺技术员审核）</p>
          </td>
        </tr>
        <tr>
          <td colspan="5">
            四、动火作业安全技术措施及现场施工组织（内容较多时可另加纸）（内容参见附录C.1）
            <el-form-item prop="measure">
              <el-input v-model="obj.measure" type="textarea" placeholder="请输入" />
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td colspan="5">
            五、动火作业单位审查意见（负责人）
            <div class="min-height100" />
            <div class="desc">
              <p>
                签字:
                <el-form-item prop="hotWorkUnitAdminUserId">
                  <el-select v-model="obj.hotWorkUnitAdminUserId" placeholder="请选择">
                    <el-option v-for="item in options" :key="item.userId" :label="item.username" :value="item.userId" />
                  </el-select>
                </el-form-item>
              </p>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="5">
            六、作业区域所在基层单位审查意见：
            <div class="min-height100" />
            <div class="desc">
              <p>
                签字:
                <el-form-item prop="basicUnitAdminUserId">
                  <el-select v-model="obj.basicUnitAdminUserId" placeholder="请选择">
                    <el-option v-for="item in options" :key="item.userId" :label="item.username" :value="item.userId" />
                  </el-select>
                </el-form-item>
              </p>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="1">七、二级单位业务主管部门审查意见</td>
          <td colspan="1">
            生产调度运行部门：
            <div class="min-height60" />
            <p>
              签字:
              <el-form-item prop="twoProductionAdminUserId">
                <el-select v-model="obj.twoProductionAdminUserId" placeholder="请选择">
                  <el-option v-for="item in options" :key="item.userId" :label="item.username" :value="item.userId" />
                </el-select>
              </el-form-item>
            </p>
          </td>
          <td colspan="2">
            资产设施管理部门（生产、管道或工程）：
            <div class="min-height60" />
            <p>
              签字:
              <el-form-item prop="towAssetsAdminUserId">
                <el-select v-model="obj.towAssetsAdminUserId" placeholder="请选择">
                  <el-option v-for="item in options" :key="item.userId" :label="item.username" :value="item.userId" />
                </el-select>
              </el-form-item>
            </p>
          </td>
          <td colspan="1">
            安全监管部门：
            <div class="min-height60" />
            <p>
              签字:
              <el-form-item prop="twoSafetyAdminUserId">
                <el-select v-model="obj.twoSafetyAdminUserId" placeholder="请选择">
                  <el-option v-for="item in options" :key="item.userId" :label="item.username" :value="item.userId" />
                </el-select>
              </el-form-item>
            </p>
          </td>
        </tr>
        <tr>
          <td colspan="5">
            八、二级单位主管领导：
            <div class="min-height100" />
            <div class="desc">
              <p>
                签字:
                <el-form-item prop="leaderAdminUserId">
                  <el-select v-model="obj.leaderAdminUserId" placeholder="请选择">
                    <el-option v-for="item in options1" :key="item.userId" :label="item.username" :value="item.userId" />
                  </el-select>
                </el-form-item>
              </p>
            </div>
          </td>
        </tr>
      </table>
    </el-form>
    <div class="botDesc">
      <p>保存单位：动火单位</p>
      <p>保存期限：一年</p>
    </div>
    <div>
      <el-button type="primary" @click="submitHandle">确认</el-button>
      <el-button @click="reset">重置</el-button>
    </div>
  </div>
</template>
<script>
import { postHandle } from '@/api'
import WiseFile from '@/components/Crud/components/wiseFile'
export default {
  components: {
    WiseFile
  },
  props: ['object'],
  data() {
    return {
      obj: {
        spaceId: '',
        name: '',
        fileUrl: null,
        serialNumber: '',
        hotApplyUnit: '',
        hotWorkStartTime: '',
        hotWorkEndTime: '',
        workAdminUserName: '',
        hotLevel: '',
        hotPlace: '',
        hotWorkUnitAdmin: '',
        hotWorkUnitGuardian: '',
        hotContent: '',
        hotWorkUnitAdminUserId: '',
        basicUnitAdminUserId: '',
        twoProductionAdminUserId: '',
        towAssetsAdminUserId: '',
        twoSafetyAdminUserId: '',
        leaderAdminUserId: '',
        sketchMap: '',
        measure: '',
        drawUser: '',
        processUser: ''
      },
      rules: {
        spaceId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        serialNumber: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        hotWorkUnitAdmin: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        basicUnitAdminUserId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        twoProductionAdminUserId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        towAssetsAdminUserId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        twoSafetyAdminUserId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        leaderAdminUserId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ],
        hotWorkUnitAdminUserId: [
          {
            required: true,
            message: '必填项不能为空',
            trigger: 'blur'
          }
        ]
      },
      dialogVisible: false,
      userList: '/api/v1/welder-uac-second/space-user-member-role-comb/get-user-info-by-roles',
      jituanList: '/api/v1/welder-sbtx-second/hot-approval-comb/list',
      addUrl: '/api/v1/welder-sbtx-second/hot-program-comb/create',
      options: '',
      options1: [],
      value: '',
      value1: [],
      passProjectData: []
    }
  },
  computed: {
    spaceId() {
      return this.$store.getters.entSpaceId
    }
  },
  created() {
    this.obj = this.object
    this.value1.push(this.object.hotWorkStartTime, this.obj.hotWorkEndTime)
    this.getOptionsItems()
    this.getEntAdminData()
    this.getPassProjectData()
  },
  methods: {
    // 获取项目发起已经通过并且还未选择动火方案的项目
    getPassProjectData() {
      let params = {
        d: {
          filters: [
            {
              field: 'hotId',
              operator: 'ISNULL',
              value: 'NULL'
            },
            {
              field: 'entSpaceId',
              operator: 'EQUALS',
              value: this.spaceId
            }
          ]
        }
      }
      // /api/v1/welder-sbtx-second/project-info
      postHandle(`/api/v1/welder-sbtx-second/project-info-comb/get-project-by-hotId/${this.spaceId}`).then(res => {
        this.passProjectData = res.result
      })
    },
    getOptionsItems() {
      let params = {
        d: {
          c: [
            {
              key: 'authToken',
              value: this.$store.getters.token
            },
            {
              key: 'entSpaceId',
              value: this.$store.getters.entSpaceId
            }
          ]
        },
        obj: {
          roleCodes: ['formalEmployee'],
          spaceId: this.spaceId,
          spaceProperty: 1
        }
      }
      if (this.userList) {
        postHandle(this.userList, params).then(res => {
          this.options = res.result
        })
      }
    },
    // 企业管理元

    getEntAdminData() {
      postHandle('/api/v1/welder-uac-second/space-user-member-role-comb/get-ent-admin/' + this.spaceId).then(res => {
        this.options1 = res.result
      })
    },
    submitHandle() {
      this.$refs['ruleForm'].validate(valid => {
        if (valid) {
          this.drawer = false
          if (this.addUrl) {
            postHandle(this.addUrl, {
              obj: this.obj
            }).then(res => {
              if (res._rd) {
                this.$message({
                  message: '创建成功',
                  type: 'success'
                })
                this.$emit('hideDijon', false)
              }
            })
          }
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    timeChange(a) {
      this.obj.hotWorkStartTime = a[0]
      this.obj.hotWorkEndTime = a[1]
    },
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
table {
  border-collapse: collapse;
  width: 100%;
  border: 1px solid;
  text-align: left;

  td {
    line-height: 22px;
    border: 1px solid;
    padding: 14px;
  }

  td:nth-child(odd) {
    width: 20%;
  }
}

.min-height100 {
  min-height: 100px;
}

.min-height60 {
  min-height: 60px;
}

.desc {
  text-align: right;
  width: 100%;

  p {
    width: 250px;
    text-align: left;
    display: inline-block;
  }
}

.botDesc {
  padding-top: 10px;
  padding-left: 100px;
}

.botDesc p {
  line-height: 40px;
}

.textRight {
  text-align: right;
  line-height: 30px;
}

.textCenter {
  text-align: center;
}

.title {
  text-align: center;
  /* line-height: 40px; */
  padding-bottom: 20px;
}

.label_put {
  width: 30%;
}
</style>
